import torch
import numpy as np
from torch import nn 
from torch.autograd import Variable
import torch.nn.functional as F
from utils import train
from torch.utils.data import DataLoader
from datetime import datetime
import Res_sensor
from Res_sensor import tf_resnet

data_train1 = np.loadtxt('data\data1.txt')
data_train2 = np.loadtxt('data\data2.txt')
data_train3 = np.loadtxt('data\data3.txt')

data_train = np.append(data_train1[:,0:-1],data_train2[:,0:-1],axis=0)
data_train = np.append(data_train,data_train3[:,0:-1],axis=0)

data_tr = DataLoader(data_train, 64, shuffle = True)
res_net = Res_sensor.net_sensor(1)
optim = torch.optim.SGD(res_net.parameters(), lr=0.001)
cre = nn.MSELoss()
Res_sensor.train_resnet(res_net, data_tr, test_data= None, num_epochs = 50, optimizer=optim,criterion=cre)

data = Variable(tf_resnet(data_train[:,0:-1]), volatile = True)
test = data[40,:,:,:]
res_net.eval()
label_test = res_net(test)
la = np.array(label_test.data,dtype='float32')
print(la[0]*1000)
print(data_train[40,-1])
torch.save(res_net.state_dict(),'weight.pth')








